# require "#{RAILS_ROOT}/app/models/exam"
# require "#{RAILS_ROOT}/app/models/user"
# require "#{RAILS_ROOT}/app/models/skill"

require "#{RAILS_ROOT}/app/classes/cat/cat_exam"
require "#{RAILS_ROOT}/app/classes/irt/irt_model"

#* user_profile.rb
#* Copyright (C) 2010  Embian Inc.
#
#  This program is free software: you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation, either version 3 of the License, or 
#  (at your option) any later version.
#  
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#  
#  You should have received a copy of the GNU General Public License
#  along with This program.  If not, see <http://www.gnu.org/licenses/>.
#  
#* Manages user profile such as examinee's ability, handled items, etc.
#* Author: KyoungMo Yang(E-mail : mo@embian.com)
#* Modified: 2010-11-30
#* References: CATExam, IRTModel, CATUser
class UserProfile
  attr_accessor :cat_model, :prev_theta
  
  #* Functionailities
  # * Constructs an instance of UserProfile class.
  #* Parameters 
  # * [user_id] : examinee's id
  #* Return
  # * An instance of UserProfile class
  #* Note
  # * N/A
  def initialize(user_id, classfication=nil)
    @user_id = user_id
    @classfication = classfication
    @cat_model = CATModel.new
    @cat_exam = CATExam.new
    @cat_exam.examinee = CATExaminee.new(user_id, [], "CAT_#{user_id}", 1)
    @crit = 0.01
    @prev_theta = nil
  end
  
  #* Functionailities
  # * Sets SEM criterion for stopping rule
  #* Parameters 
  # * [value] : crit
  #* Return
  # * N/A
  #* Note
  # * N/A
  def crit=(value)
    @crit = value
  end
  
  #* Functionailities
  # * Returns SEM criterion (Default value is 0.001)
  #* Parameters 
  # * N/A
  #* Return
  # * [crit] : crit
  #* Note
  # * N/A
  def crit
    @crit
  end
  
  #* Functionailities
  # * Returns user(examinee's) id
  #* Parameters 
  # * N/A
  #* Return
  # * [user_id] : examinee's id
  #* Note
  # * N/A
  def user_id
    @user_id
  end
  
  #* Functionailities
  # * Returns an instance of User Model
  #* Parameters 
  # * N/A
  #* Return
  # * [user] : an instance of User Model
  #* Note
  # * N/A
  def user
    @user
  end
  
  #* Functionailities
  # * Get classfication
  #* Parameters 
  # * N/A
  #* Return
  # * [user_id] : examinee's id
  #* Note
  # * N/A
  def classfication
    @classfication
  end
  
  #* Functionailities
  # * Sets user(examinee's) theta
  #* Parameters 
  # * [value] : examinee's theta
  #* Return
  # * N/A
  #* Note
  # * N/A
  def theta=(value)
    @cat_exam.examinee.theta = value.to_f
    # @user.exam.theta = value
    # raise @user.exam.errors.full_messages.join("\n") unless @user.exam.save
  end
  
  #* Functionailities
  # * Returns user(examinee's) theta
  #* Parameters 
  # * N/A
  #* Return
  # * [theta] : examinee's theta
  #* Note
  # * N/A
  def theta
    return @cat_exam.examinee.theta.to_f
  end
  
  #* Functionailities
  # * Returns an instance of CATExam
  #* Parameters 
  # * N/A
  #* Return
  # * [exam] : an instance of CatExam
  #* Note
  # * N/A
  def exam
    @cat_exam
  end
end